<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  	<base href="<%=basePath%>">  
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<!--<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	 <meta http-equiv="description" content="This is my page">-->
  
	<title>DaWu</title>
	<link rel="stylesheet" type="text/css" href="css/index.css">
	<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="js/base64.min.js"></script>
	<script type="text/javascript" src="js/jquery-cookie.js"></script>
	<script language="JavaScript" type="text/javascript" src="js/func.js"></script>
	<script type="text/javascript" src="lang/b28n.js"></script>
	<script type="text/javascript"></script>
</head>
<body>
	<div class="header header_login">
	    <h1 id="product-log"></h1>
	</div>
	<div class="login_body">
		<div class="loginbox">
			<form class="loginform" type="POST" name="LoginForm" action=""> 
				<div id="massage_text"></div>
				<div class="username loginline">
					<i></i>
					<input	type="text" name="userName">
				</div>
				<div class="password loginline">
					<i></i>
					<input	type="password" name="password">
				</div>
				<div class="submit" onclick="preSubmit();"><span id="login"> 登录 </span></div>
			</form>
		</div>
	</div>
</body>
<script>

	function preSubmit() {
		if(document.forms[0].userName.value=="")
		{
			$('#massage_text').text('请输入用户名。');
			document.forms[0].userName.focus();
			return false;
		}
		if(document.forms[0].password.value=="")
		{
			$('#massage_text').text('请输入密码。');
			document.forms[0].password.focus();
			return false;
		}
		if(document.forms[0].password.value.match(/^[0-9A-Za-z_.@*-]{1,32}$/)==null)
	        {
	                $('#massage_text').text("只能输入数字、字母和_.@-*字符。");
		        return false;
	        }
        var password=document.forms[0].password.value;
		password = MD5(password);
	    document.forms[0].password.value = utf16to8(password); 
		var loginData = "{\"username\":\"" + document.forms[0].userName.value + "\",\"password\":\"" + 
		    document.forms[0].password.value+"\"}";		
		var authSend="{\"dwsignatureCheck\":\""+base64encode(loginData)+"\"}";
//		var host="http://10.10.10.254:1118"
        $.ajax({
            url: "/dw/Dwbrowser",
            type: "POST",
            timeout: 180000,
            data: authSend,
            dataType: "text",
//			async: true,
            error: function() {
			    $('#massage_text').text('网络错误。'); 
                return false;
            },
            complete: function() {
              
              if (status === 'timeout') {
                $('#massage_text').text('超时。');
				this.abort();
              }
            },
            success: function(auReturn) {
//                console.log(auReturn);
				var auRe;
//                authReturn = authReturn64;
//				authReturn = JSON.parse(authReturn64);               
                auRe = jQuery.parseJSON(Base64.decode(auReturn));
//				console.log(auRe);
                if(auRe.res === "success")
				{
//                    console.log("success");
					var date = new Date();
		            date.setTime(date.getTime() + (60 * 60* 1000));
		            $.cookie('logon',true,{expires: date});
					window.location.href='/dw/home.jsp';
//                    document.forms[0].submit();
                }else if(auRe.res === "deny1")
				{
			        $('#massage_text').text('用户名错，请重新输入。'); 
                    return false;
                }else if(auRe.res === "deny2")
				{
			        $('#massage_text').text('密码错，请重新输入。'); 
                    return false;
                }else if(auRe.res === "deny3")
				{
			        $('#massage_text').text('请输入用户名。'); 
                    return false;
                }else if(auRe.res === "deny4")
				{
			        $('#massage_text').text('请输入密码。'); 
                    return false;
                }else if(auRe.res === "deny5")
				{
			        $('#massage_text').text('出错了。重启或联系管理员。'); 
                    return false;
                }else if(auRe.res === "deny6")
				{
			        $('#massage_text').text('用户名或密码太长。'); 
                    return false;
                }
                				
            }
        });
	}
	$(document).keydown(function(e){
		if(e.keyCode === 13){//
			preSubmit();
		}
	});
    
</script>
</html>